//
//  DayDetailViewController.m
//  ios-supplier
//
//  Created by Benlai on 15/7/24.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "DayDetailViewController.h"
#import "CompleteOrderListProxy.h"
#import "OrderDetailController.h"

@interface DayDetailViewController ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong) CompleteOrderListProxy *proxy;
@property (nonatomic, strong) NSDictionary * currentNotificationInfo;
@end

@implementation DayDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"当日明细";
    
    CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    self.proxy = [[CompleteOrderListProxy alloc]initWithFrame: frame orderType: @"complete" date: self.date];
    [self.view addSubview:self.proxy];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectDayOrderItem:) name:@"selectDayOrderItem" object:nil];
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationItem setLeftBarButtonItem: [self createBackView]];
    
    
    // Do any additional setup after loading the view.
}

- (UIBarButtonItem *)createBackView
{
    UIButton *leftButtonItem = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButtonItem.frame = CGRectMake(0, 0, 11, 20);
    [leftButtonItem setBackgroundImage:[UIImage imageNamed:@"icon-Back"] forState:UIControlStateNormal];
    [leftButtonItem setImageEdgeInsets: UIEdgeInsetsMake((19 - 11) / 2, 0, (19 - 11) / 2, 0)];
    [leftButtonItem addTarget:self action:@selector(leftButtonItemClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:leftButtonItem];
    return item;
}

-(void)leftButtonItemClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)selectDayOrderItem:(NSNotification *)notification
{
    self.currentNotificationInfo = notification.userInfo;
    
    NSString * currentOrderType = [self.currentNotificationInfo objectForKey:@"orderType"];
    JFBOrderDS * currentOrder = [self.currentNotificationInfo objectForKey:@"order"];
    currentOrder.orderType = currentOrderType;
    
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"OrderFlow" bundle: nil];
    OrderDetailController * orderDetailVC = (OrderDetailController *)[storyBoard instantiateViewControllerWithIdentifier:@"detailVCIdentity"];
    
    orderDetailVC.isDayDetail = YES;
    orderDetailVC.hidesBottomBarWhenPushed = true;
    orderDetailVC.order = currentOrder;
    orderDetailVC.refreshDelegate = [self.currentNotificationInfo objectForKey:@"refreshDelegate"];
   
    [self.navigationController pushViewController:orderDetailVC animated:YES];
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
